package de.negativrekord.blockworld;

import cc.creativecomputing.control.CCControl;
import cc.creativecomputing.graphics.CCCamera;
import cc.creativecomputing.graphics.CCGraphics;
import cc.creativecomputing.math.CCMath;
import cc.creativecomputing.math.CCMatrix3f;
import cc.creativecomputing.math.CCVector2f;
import cc.creativecomputing.math.CCVector3f;

public class CameraWrapper {

	CCCamera camera;
	@CCControl(name="dir", min=0, max=CCMath.TWO_PI)
	float dir = 0;
	
	float x,y;
	float currentAngle = 0.05f;
	int cnt = 0;
	int lr = -1;
	float speed = -2f;
	

	public CameraWrapper (CCGraphics g) {
		camera = g.camera();
	}
	
	float posx() {
		return camera.position().x;
	}
	
	float posy() {
		return camera.position().y;
	}
	
	public void target (CCVector3f theTarget) {
		target = theTarget;
	}
	
	public void up (CCVector3f theUp) {
		up = theUp;
	}
	
	public void changeDirXY (float angle) {
		x = CCMath.cos(angle);
		y = CCMath.sin(angle);
		
		camera.target (10000*x, 10000*y, 0);
		camera.up(new CCVector3f(0,0,1));
		camera.position().x += speed*x;
		camera.position().y += speed*y;
		
	}
	
	CCVector3f target;
	CCVector3f up;
	
	
	public void pan (float angle) {
		float c = CCMath.cos(angle);
		float s = CCMath.sin(angle);
		
		target = new CCVector3f (s,0,-c).scale(10000);
		up     = new CCVector3f (0,1,0);
		
		//camera.target (new CCVector3f(u*10000,d*10000,0));
		//camera.up(new CCVector3f(0,0,1));
	}
	
	
	public void tiltUD (float angle) {
		
		float c = CCMath.cos(angle);
		float s = CCMath.sin(angle);
		
		target.set(c*0,s,c).scale(1000);
		up.set(-s*0,c,-s);
		
		/*
		CCVector3f target = new CCVector3f (c, -s, 0);
		CCVector3f up = new CCVector3f (s, c, 0);
		*/
		
		//camera.target (target.scale(10000));
		//camera.up(up);
	}
	
	
	public void tiltLR (float angle) {

//		CCVector3f up  = new CCVector3f (0,0,1);
//		CCVector3f dir = new CCVector3f (camera.target()).normalize();

		float c = CCMath.cos(angle);
		float s = CCMath.sin(angle);
//		up.rotate (dir.x, dir.y, dir.z, angle);
//		camera.up (up);
		
		target.scale(new CCVector3f(c,s,c));
	}
	
	public void update() {
		camera.up(up);
		camera.target(target);
	}
	
	public void position (CCVector3f thePos) {
		camera.position(thePos);
	}
}
